package ru.xpparty.scanner;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by IntelliJ IDEA.
 * User: vanger
 * Date: 19.12.10
 * Time: 16:19
 * To change this template use File | Settings | File Templates.
 */
public class ParserImpl implements Parser {

    @Override
    public Collection<Host> parse(String host, String port) {
        Collection<Host> result = new ArrayList<Host>();
        String[] interval = port.split("-");
        if (interval.length == 1) {
            result.add(new Host(host, Integer.parseInt(interval[0])));
        } else if (interval.length == 2) {
            int begin = Integer.parseInt(interval[0]);
            int end = Integer.parseInt(interval[1]);
            for (int i = begin; i <= end; i++) {
                result.add(new Host(host, i));
            }
        }

        return result;

    }
}
